﻿using DataAccess.DAL;
using DataAccess.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;  
namespace Web.Controllers
{
    public class HomeController : BaseController
    {
        //
        // GET: /Home/
        public ActionResult Index()
        {
             
          //string[] a=  ShortenUrl.AddUrl(new string[] { "http://baidu.com" });
            OrdersDAL oDal = new OrdersDAL();
            var ts= oDal.GetPromoterTodayStatistics(UserSession.user_id);
            //统计
            ViewBag.TS = ts;

            //排行榜
            var phb= new ProductEffectDAL().GetRankingList(UserSession.user_id);

            ViewBag.phb = phb;
            return View();
        }
        [HttpPost]
        public JsonResult GetStatistics_List()
        {

            DataAccess.DTO.Result res = new DataAccess.DTO.Result() { State=false, Message="请求失败" };

            var Statistics_List = new ProductEffectDAL().Statistics_List_M(UserSession.user_id, DateTime.Now.AddMonths(-2).ToString("yyyy-MM-01"));

            res.Message = "请求成功";
            res.State = true;
            var this_month = from l in Statistics_List.Where(l => l.CreateDate.Month == DateTime.Now.Month)
                             select new { riqi = l.CreateDate.ToString("yyyy-MM-dd"), estimate = l.Estimate, income = l.Income };
 
            var last_month = from l in Statistics_List.Where(l => l.CreateDate.Month == DateTime.Now.AddMonths(-1).Month)
                             select new { riqi = l.CreateDate.ToString("yyyy-MM-dd"), estimate = l.Estimate, income = l.Income };

            res.Datas = new { this_month = this_month, last_month = last_month };


            return Json(res);
        }


        public ActionResult Edit()
        {
            return View();
        }


        public ActionResult Form()
        {
            return View();
        }

        public ActionResult List()
        {
            return View();
        }

        public ActionResult Login()
        {
            return View();
        }
        public ActionResult Survey()
        {
            return View();
        }

        public ActionResult ProductList()
        {
            return View();
        }
    }
}